package com.neusoft.databus.common.connection;

import com.neusoft.bizcore.web.utils.JsonUtils;

import lombok.Getter;
import lombok.Setter;

/**
 * SNMP连接配置
 *
 * @author naxiang
 */
@Getter
@Setter
public class SnmpConnection extends AbstractConnection {
    private static final long serialVersionUID = 1L;
    public String ipAddress;
    // 端口
    public int port;
    // 区域
    public String community = "public";
    // 重试次数
    public int retry = 0;
    // 超时时长
    public int timeout = 1000;
    // 版本
    public int version = 1;
    // v3版本读数据密码
    public String authPass;
    // v3版本写数据密码
    public String privPass;
    // v3版本用户名
    public String user;
    // v3版本安全级别
    public String level;
    //v3认证加密方式 md5 sha sha224 sha256 sha384 sha512 默认md5
    public String authProtocol;
    //v3授权加密方式 des aes128 aes192 aes256 默认des
    public String privProtocol;
    // 连接池标识位
    public int seq = 0;
    // SNMP一次get指标数
    public int batchSize = 100;

    @Override
    public int hashCode() {
        return (this.ipAddress + ":" + this.port + ":" + this.community + ":" + this.seq).hashCode();
    }

    @Override
    public boolean equals(final Object o) {
        if (o instanceof SnmpConnection) {
            return this.hashCode() == ((SnmpConnection) o).hashCode();
        }
        return false;
    }

    @Override
    public SnmpConnection asUsedConnection() {
        return this;
    }

    public String getTransportProtocolDependentAddress() {
        final StringBuilder sb = new StringBuilder();
        sb.append("UDP:").append(this.ipAddress).append("/").append(this.port);
        return sb.toString();
    }

    @Override
    public String toString() {
        return JsonUtils.pojoToJson(this);
    }

}
